<?php
	/*		View отвечает за отображение итоговой страницы
	 * 	Он является оберткой для доступа к tpl->fetch
	 * 
	 * 
	 * 
	 */
	 
	class view extends service {

		public function add_viewport($name){
			$viewport_name = "viewport_".$name;
			
			$relpath = "viewports"._DRS."{$name}.viewport.php";
			
			if ($path = context::get("path")->locate($relpath)){
				
				require_once($path._DRS.$relpath);
				
				$viewport = new $viewport_name;
				$viewport->set_name($name);
			
				#$viewport->exec();
			
				$this->viewport_stack[] = $viewport;
			}else{
				context::get("io")->debug("unable to locate {$relpath}",IO_DEBUG_ERROR);
			}
		}
		
		public function flush(){
			#flush viewport stack without a mercy
			$this->viewport_stack = array();
		}

		public function display($content = null){
			echo $this->fetch($content);
		}
		
		public function fetch($content = null){
			if ($this->viewport_stack){
				foreach ($this->viewport_stack as $viewport){
					
					$viewport->exec();
					$content = $viewport->fetch($content);
				}
			}
			return $content;
		}
	}
?>
